package com.hpf.lease.web.admin.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hpf.lease.common.config.CommonException;
import com.hpf.lease.common.result.ResultCodeEnum;
import com.hpf.lease.model.bean.LeaseTerm;
import com.hpf.lease.web.admin.mapper.LeaseTermMapper;
import com.hpf.lease.web.admin.service.LeaseTermService;
import org.springframework.stereotype.Service;

/**
* @author GOD
* @description 针对表【lease_term(租期)】的数据库操作Service实现
* @createDate 2024-08-29 15:00:50
*/
@Service
public class LeaseTermServiceImpl extends ServiceImpl<LeaseTermMapper, LeaseTerm>
    implements LeaseTermService {

    @Override
    public boolean saveOrUpdateInfo(LeaseTerm term) {
        Long id = term.getId() == null ? -1L : term.getId();
        LeaseTerm one = this.getOne(Wrappers.lambdaQuery(LeaseTerm.class)
                .eq(LeaseTerm::getMonthCount, term.getMonthCount())
                .eq(LeaseTerm::getUnit, term.getUnit())
                .last("limit 1"));
        if (one != null && one.getId().equals(id)){
            throw new CommonException(ResultCodeEnum.LEASE_TERM_EXISTS_ERROR);
        }
        return this.saveOrUpdate(term);
    }
}




